


import axios from 'axios';
import { navlist } from '@/app/lib/placeholder-data'

export async function fetchTopNavList() {
    try {
        // console.log('fetchTopNavList', process.env.API_URL, process.env.NEXT_PUBLIC_API_URL)
        // const res = await axios.post(`${process.env.NEXT_PUBLIC_API_URL}/api/Category/List`);
        // const data = res.data.data;
        // return data;
        const staticData = [
            { id:1, name:'学习签证', component:'study'},
            { id:3, name:'移民签证', component:'immigrant'},
            { id:4, name:'疑难杂症', component:'problem'},
            { id:5, name:'拒签处理', component:'deny'},
            { id:6, name:'联系我们', component:'contact'},
        ]
        let arr = [{ id: 0, name: '网站首页', href: '/'}]
        for(let item of navlist){
            let index = staticData.findIndex((v)=>v.id==item.id);
            if(index>-1){
                item.href = `/${staticData[index].component}`
            }
            if(item.child_category && item.child_category.length>0){
                for(let child of item.child_category){
                    let cindex = staticData.findIndex((v)=>v.id==child.pid);
                    if(cindex>-1){
                        child.href=`/${staticData[cindex].component}/project/${child.id}` 
                    }
                }
            }
            arr.push(item)
        }
        
        console.log('fetchTopNavList', arr);
        return arr;        
    } catch (error) {
        console.error('fetchTopNavList Error:', error);
        throw new Error('Failed to fetch TopNavList.');
    }
}